<?php
/* 
 * TAO KANG -- 897637176
 */
namespace app\blog\controller;
use cmf\controller\AdminBaseController;
use think\Validate;
use think\Db;

class PrintController extends AdminBaseController{
    public function index(){
        return $this->fetch();
    }
    public function prlist(){
        $list = Db::name("print")->field('print_id,print_name,print_namebq,print_namejj')->select();
        $this->assign('list',$list);
        return $this->fetch();
    }
    public function addpost(){
        return $this->fetch();
    }
    public function adddate(){
        if($this->request->isPost()){
            $data = $this->request->post();
            $shuju = array();
            $shuju['print_name'] = $data['print_name'];
            $shuju['print_namebq'] = $data['print_namebq'];
            $shuju['print_namejj'] = $data['print_namejj'];
            $panduan = Db::name("print")->field('print_name,print_namebq')->find();
            if($panduan == null){
            $result = Db::name('print')->insert($shuju);
            if($result){
                $this->success(lang('保存成功'), "print/prlist");
            }else{
                $this->error(lang('保存失败'), "print/prlist");
            }
            }else{
                $this->success(lang("已经添加过了!"), "print/prlist");
            }
        }
    }
    public function updatelist(){
        $printid = $this->request->param("nav_id");
        $list = Db::name('print')->where('print_id='.$printid)->field("print_name,print_namebq,print_namejj,print_id")->find();
        $this->assign('list',$list);
        return $this->fetch();
    }
    public function updapost(){
        if($this->request->isPost()){
            $data = $this->request->post();
            $shuju = array();
            $shuju['print_name'] = $data['print_name'];
            $shuju['print_namebq'] = $data['print_namebq'];
            $shuju['print_namejj'] = $data['print_namejj'];
            $result = Db::name('print')->where("print_id=".$data['print_id'])->update($shuju);
            if($result){
                $this->success(lang('修改成功'), "print/prlist");
            }else{
                $this->error(lang('修改失败'), "print/prlist");
            }
        }
    }
}
